<?php
class Location extends AppModel {
	var $name = 'Location';
	var $displayField = 'item_id';
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $validate = array(
    	'pic' => array( 
        	'rule' => 'notEmpty',
        	'message' => 'This field cannot be left blank'
    	)
	);
	
	
	var $belongsTo = array(
		'Item' => array(
			'className' => 'Item',
			'foreignKey' => 'item_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'District' => array(
			'className' => 'District',
			'foreignKey' => 'district_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	
	/**
	 * 
	 * Function to return all available items based on category
	 * @return array $item_id
	 * @param int $district_id
	 */
	function getItemFromDistrict ($district_id) {
		$conditions = array('Location.active'=>1,'district_id'=>$district_id);
		$locations = $this->find('list',array('conditions'=>$conditions));
		return $locations;
	}
	
	public function getListItemBasedOnLocation($district_id) {
	}

	function afterFind($results) {
		foreach ($results as $key => $val) {
			if (isset($val['Location']['date'])) {
				$results[$key]['Location']['date'] = $this->dateFormatAfterFind($val['Location']['date']);
		
			}
	
		}
	
		return $results;
	}

	function dateFormatAfterFind($dateString) {
		return date('d-M-Y', strtotime($dateString));
		}
				
	}

